package eleven.senven.hpb.ui;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.RadioGroup;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

import eleven.senven.hpb.R;
import eleven.senven.hpb.fragment.ClassificationFragment;
import eleven.senven.hpb.fragment.ClassificationFragment_;
import eleven.senven.hpb.fragment.CommunityFragment;
import eleven.senven.hpb.fragment.MineFragment;
import eleven.senven.hpb.fragment.RecommendationFragment;
import eleven.senven.hpb.utils.FragmentTabUtils;

@EActivity(R.layout.activity_main)
public class MainActivity extends AppCompatActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener {
    @ViewById(R.id.rg)
    RadioGroup rg;
    @ViewById(R.id.fragment_holder)
    FrameLayout fragment_holder;
    private List<Fragment> fragments = new ArrayList<>();
    @AfterViews
    void afterview(){
        fragments.add ( new CommunityFragment());
        fragments.add(new ClassificationFragment_());
        fragments.add(new Fragment());//空布局
        fragments.add(new RecommendationFragment());
        fragments.add(new MineFragment());
        new FragmentTabUtils(rg,getSupportFragmentManager(),fragments,R.id.fragment_holder).setOnRgsExtraCheckedChangedListener(this);

    }
    @Click(R.id.image_camaral)
    void click(){
        View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_popupwid, null);
        final  PopupWindow popupWindow = new PopupWindow(view,
                500, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        view.findViewById(R.id.up).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivity(intent);
                popupWindow.dismiss();
            }
        });
        view.findViewById(R.id.select).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivity(intent); // RESULT_LOAD_IMAGE:Activity的标志。自已
                popupWindow.dismiss();
            }
        });
        popupWindow.setTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.showAtLocation(fragment_holder, Gravity.CENTER, 0, 240);
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {

    }
}
